﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BAL;
using Common;
using System.Text;
using System.Text.RegularExpressions;
namespace Web
{
    public partial class ChartScorePrint : System.Web.UI.Page
    {
        protected int examroomid = 0, studentid = 0;

        //首页
        protected string ExamRoomId = "", ExamRoomDate = "";
        protected string AreaName = "", SchoolName = "", GradeName = "", ClassName = "";
        protected string StudentName = "", StudentSex = "", StudentNumber = "";

        //一页
        protected string ViewMyScore = "";
        protected string ViewClassEverage = "", ViewGClassMax = "", ViewClassNumber = "";
        protected string ViewGradeEverage = "", ViewGradeMax = "", ViewGradeNumber = "";
        protected string ViewAreaEverage = "", ViewAreaMax = "", ViewAreaNumber = "";
        protected string ChartString = "";
        protected string bcnm = "";
        protected string comment = "";
        
        //二页
        protected string mychart = "", classchart = "", gradechart = "", areachart = "", allchart = "";

        protected string piechart = "", barchart = "";

        protected string piechart1 = "", barchart1 = "";

        protected string piechart2 = "", barchart2 = "";

        protected static ExamPaperInfo ExamPaper_Info = new ExamPaperInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(this.Request, "StatistScore"))
            {
                Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                Response.Redirect("login.aspx");
                Response.End();
            }
            if (!PageValidate.QueryStringIsEmpty("studentid"))
            {
                try
                {
                    studentid = int.Parse(PageValidate.QueryString("studentid"));
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    Response.End();
                }
            }
            if (!PageValidate.QueryStringIsEmpty("examroomid"))
            {
                try
                {
                    examroomid = int.Parse(PageValidate.QueryString("examroomid"));
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    Response.End();
                }
            }
            if (!IsPostBack)
            {
                if (examroomid > 0 && studentid > 0)
                {
                    ExamRoomInfo examroominfo = ExamRoom.GetSingleInfo(examroomid);
                    StudentInfo studentinfo = Student.GetSingleInfo(studentid);
                    IList<StudentScoreExtendInfo> infos = new List<StudentScoreExtendInfo>();
                    infos = StudentScoreExtend.GetList(examroominfo.Id, 0, 0, 0, 0, 0, 0, 0);
                    StudentScoreExtendInfo myInfo = infos.First(t => t.StudentId == studentid);
                    if (myInfo.CountScore == myInfo.ExamPaperScore)
                    {
                        AnswerAnalyzeList.InnerHtml = "<tr><td colspan='6'>恭喜你得满分，所有答案全部正确</td></tr>";
                    }
                    else
                    {
                        AnswerAnalyzeList.InnerHtml = AnswerAnalyze(myInfo, examroominfo.ExamPaperId);
                    }
                    ExamPaper_Info = BAL.ExamPaper.GetT1(examroominfo.ExamPaperId);
                    LoadQuestion(examroominfo.ExamPaperId);

                    onePage(studentinfo, examroominfo);
                    towPage(examroominfo, infos, myInfo);
                    threePage(infos, myInfo);
                    fourPage(infos, myInfo);
                    fivePage(infos, myInfo);
                    sixPage(infos, myInfo);
                    sevenPage(infos, myInfo);
                }
                else
                {
                    Response.Redirect("AdminExamRoom.aspx");
                }
            }
        }

        private void onePage(StudentInfo studentInfo, ExamRoomInfo examroominfo)
        {
            ExamRoomId = examroominfo.CreateDate.ToShortDateString() + "-" + examroominfo.Id.ToString();
            ExamRoomDate = examroominfo.ExamStartDate.Value.ToShortDateString() + "-" + examroominfo.ExamEndDate.Value.ToShortDateString();
            SchoolName = School.GetSingleInfo(studentInfo.SchoolId).Name;
            GradeName = Grade.GetSingleInfo(studentInfo.GradeId).Name;
            AreaName = Area.GetSingleInfo(studentInfo.AreaId).Name;
            ClassName = TClass.GetSingleInfo(studentInfo.ClassId).Name;
            StudentName = studentInfo.Name;
            StudentSex = studentInfo.Sex == 0 ? "女" : "男";
            StudentNumber = studentInfo.Number;
        }

        private void towPage(ExamRoomInfo examroominfo, IList<StudentScoreExtendInfo> infos, StudentScoreExtendInfo myInfo)
        {
            comment = examroominfo.Comment;
            ViewMyScore = myInfo.CountScore.ToString();
            ClassCount(infos, myInfo.ClassId);
            GradeCount(infos, myInfo.GradeId);
            AreaCount(infos, myInfo.AreaId);
            if (myInfo.CountScore >= 85)
            {
                bcnm = "<span class='face_a' title='优'>优</span>【优】";
            }
            else if (myInfo.CountScore >= 70)
            {
                bcnm = "<span class='face_b' title='良'>良</span>【良】";
            }
            else if (myInfo.CountScore >= 60)
            {
                bcnm = "<span class='face_c' title='中'>中</span>【中】";
            }
            else if (myInfo.CountScore < 60)
            {
                bcnm = "<span class='face_d' title='差'>差</span>【差】";
            }
        }

        private void threePage(IList<StudentScoreExtendInfo> infos, StudentScoreExtendInfo myInfo)
        {
            IList<KnowledgeInfo> listKnowledge = GetKnowledgeMode(myInfo.SubjectId);
            IList<QuestionInfo> listQuestion = GetQuestion(myInfo.ExamPaperId);

            StringBuilder sb = new StringBuilder();
            int number = 1;
            foreach (KnowledgeInfo know in listKnowledge)
            {
                decimal questScoreCount = 0;
                IList<int> questIds = new List<int>();
                foreach (QuestionInfo quest in listQuestion)
                {
                    if (quest.KnowId == know.Id)
                    {
                        questScoreCount += quest.Score;
                        questIds.Add(quest.Id);

                    }
                    else if (know.ChildKnowledgeInfos.Count > 0)
                    {
                        IList<int> ids = know.ChildKnowledgeInfos.Select(t => t.Id).ToList();
                        if (GetArray<int>.Get(ids).Contains(quest.KnowId))
                        {
                            questScoreCount += quest.Score;
                            questIds.Add(quest.Id);
                        }
                        else
                        {
                            foreach (KnowledgeInfo n in know.ChildKnowledgeInfos)
                            {
                                if (n.ChildKnowledgeInfos.Count > 0)
                                {
                                    IList<int> childids = n.ChildKnowledgeInfos.Select(t => t.Id).ToList();
                                    if (GetArray<int>.Get(childids).Contains(quest.KnowId))
                                    {
                                        questScoreCount += quest.Score;
                                        questIds.Add(quest.Id);
                                    }
                                }
                            }
                        }
                    }
                }
                if (questIds.Count == 0)
                {
                    continue;
                }
                string[] arrScore = GetClassScoreByQuest(infos, myInfo.StudentId, myInfo.ClassId, myInfo.GradeId, myInfo.AreaId, questIds);
                string percentMy = "0";
                string percentClass = "0";
                string percentGrade = "0";
                string percentArea = "0";
                if (arrScore[0] != "0")
                {
                    percentMy = Math.Round(decimal.Parse(arrScore[0]) / questScoreCount * 100).ToString() + "%";
                    mychart += Math.Round(decimal.Parse(arrScore[0]) / questScoreCount * 100).ToString() + ",";
                }
                else
                {
                    mychart += "0,";
                }
                if (arrScore[1] != "0")
                {
                    percentClass = Math.Round(decimal.Parse(arrScore[1]) / (questScoreCount * int.Parse(arrScore[4])) * 100).ToString() + "%";
                    classchart += Math.Round(decimal.Parse(arrScore[1]) / (questScoreCount * int.Parse(arrScore[4])) * 100).ToString() + ",";
                }
                else
                {
                    classchart += "0,";
                }
                if (arrScore[2] != "0")
                {
                    percentGrade = Math.Round(decimal.Parse(arrScore[2]) / (questScoreCount * int.Parse(arrScore[5])) * 100).ToString() + "%";
                    gradechart += Math.Round(decimal.Parse(arrScore[2]) / (questScoreCount * int.Parse(arrScore[5])) * 100).ToString() + ",";
                }
                else
                {
                    gradechart += "0,";
                }
                if (arrScore[3] != "0")
                {
                    percentArea = Math.Round(decimal.Parse(arrScore[3]) / (questScoreCount * int.Parse(arrScore[6])) * 100).ToString() + "%";
                    areachart += Math.Round(decimal.Parse(arrScore[3]) / (questScoreCount * int.Parse(arrScore[6])) * 100).ToString() + ",";
                }
                else
                {
                    areachart += "0,";
                }
                sb.Append("<tr>");
                sb.Append("<td>");
                sb.Append(number);
                sb.Append("</td>");
                sb.Append("<td class='text_left'>");
                sb.Append(know.Name);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questIds.Count.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questScoreCount.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(arrScore[0]);
                sb.Append(".00</td>");
                sb.Append("<td>");
                sb.Append(percentMy);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentClass);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentGrade);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentArea);
                sb.Append("</td>");
                sb.Append("</tr>");
                number++;
            }
            this.KnowledgeList.InnerHtml = sb.ToString();
            mychart = PageValidate.IsEmpty(mychart) ? "" : mychart.Substring(0, mychart.Length - 1);
            classchart = PageValidate.IsEmpty(classchart) ? "" : classchart.Substring(0, classchart.Length - 1);
            gradechart = PageValidate.IsEmpty(gradechart) ? "" : gradechart.Substring(0, gradechart.Length - 1);
            areachart = PageValidate.IsEmpty(areachart) ? "" : areachart.Substring(0, areachart.Length - 1);
        }

        private void fourPage(IList<StudentScoreExtendInfo> infos, StudentScoreExtendInfo myInfo)
        {
            IList<KnowledgeInfo> listKnowledge = GetKnowledgeModePoint(myInfo.SubjectId);
            IList<QuestionInfo> listQuestion = GetQuestion(myInfo.ExamPaperId);

            StringBuilder sb = new StringBuilder();
            foreach (KnowledgeInfo know in listKnowledge)
            {
                decimal questScoreCount = 0;
                IList<int> questIds = new List<int>();
                foreach (QuestionInfo quest in listQuestion)
                {
                    if (quest.KnowId == know.Id)
                    {
                        questScoreCount += quest.Score;
                        questIds.Add(quest.Id);

                    }
                    else if (know.ParentKnowledgeInfo != null)
                    {
                        if (know.ParentKnowledgeInfo.Id == quest.KnowId)
                        {
                            questScoreCount += quest.Score;
                            questIds.Add(quest.Id);
                        }
                        else if (know.ParentKnowledgeInfo.ParentKnowledgeInfo != null)
                        {

                            if (know.ParentKnowledgeInfo.ParentKnowledgeInfo.Id == quest.KnowId)
                            {
                                questScoreCount += quest.Score;
                                questIds.Add(quest.Id);
                            }
                        }
                    }
                }
                if (questIds.Count == 0)
                {
                    continue;
                }
                string[] arrScore = GetClassScoreByQuest(infos, myInfo.StudentId, myInfo.ClassId, myInfo.GradeId, myInfo.AreaId, questIds);
                string percentMy = "0";
                string percentClass = "0";
                string percentGrade = "0";
                string percentArea = "0";
                if (arrScore[0] != "0")
                {
                    percentMy = Math.Round(decimal.Parse(arrScore[0]) / questScoreCount * 100).ToString() + "%";
                }
                if (arrScore[1] != "0")
                {
                    percentClass = Math.Round(decimal.Parse(arrScore[1]) / (questScoreCount * int.Parse(arrScore[4])) * 100).ToString() + "%";
                }
                if (arrScore[2] != "0")
                {
                    percentGrade = Math.Round(decimal.Parse(arrScore[2]) / (questScoreCount * int.Parse(arrScore[5])) * 100).ToString() + "%";
                }
                if (arrScore[3] != "0")
                {
                    percentArea = Math.Round(decimal.Parse(arrScore[3]) / (questScoreCount * int.Parse(arrScore[6])) * 100).ToString() + "%";
                }
                sb.Append("<tr>");
                sb.Append("<td class='text_left'>");
                sb.Append(know.Name);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questIds.Count.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questScoreCount.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(arrScore[0]);
                sb.Append(".00</td>");
                sb.Append("<td>");
                sb.Append(percentMy);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentClass);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentGrade);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentArea);
                sb.Append("</td>");
                sb.Append("</tr>");
            }
            this.KnowledgePointList.InnerHtml = sb.ToString();
        }

        private void fivePage(IList<StudentScoreExtendInfo> infos, StudentScoreExtendInfo myInfo)
        {
            IList<CognitiveLevelInfo> listCognitiveLevel = GetCognitiveLeve();
            IList<QuestionInfo> listQuestion = GetQuestion(myInfo.ExamPaperId);

            StringBuilder sb = new StringBuilder();
            foreach (CognitiveLevelInfo cognitive in listCognitiveLevel)
            {
                decimal questScoreCount = 0;
                IList<int> questIds = new List<int>();
                foreach (QuestionInfo quest in listQuestion)
                {
                    if (quest.CognitiveLevelId == cognitive.Id)
                    {
                        questScoreCount += quest.Score;
                        questIds.Add(quest.Id);

                    }
                }
                if (questIds.Count == 0)
                {
                    continue;
                }
                piechart += "['" + cognitive.Name + "'," + questIds.Count + "],";
                string[] arrScore = GetScoreByQuest(infos, myInfo.StudentId, myInfo.ClassId, myInfo.GradeId, myInfo.AreaId, questIds);
                string percentMy = "0";
                string percentClass = "0";
                string percentGrade = "0";
                string percentArea = "0";
                if (arrScore[0] != "0")
                {
                    percentMy = Math.Round(decimal.Parse(arrScore[0]) / questScoreCount * 100).ToString() + "%";
                }
                if (arrScore[1] != "0")
                {
                    percentClass = Math.Round(decimal.Parse(arrScore[1]) / (questScoreCount * int.Parse(arrScore[4])) * 100).ToString() + "%";
                }
                if (arrScore[2] != "0")
                {
                    percentGrade = Math.Round(decimal.Parse(arrScore[2]) / (questScoreCount * int.Parse(arrScore[5])) * 100).ToString() + "%";
                }
                if (arrScore[3] != "0")
                {
                    percentArea = Math.Round(decimal.Parse(arrScore[3]) / (questScoreCount * int.Parse(arrScore[6])) * 100).ToString() + "%";
                }
                barchart += "['" + cognitive.Name + "'," + percentMy.Replace("%", "") + "],";
                sb.Append("<tr>");
                sb.Append("<td align='left'>");
                sb.Append(cognitive.Name);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questIds.Count.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questScoreCount.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(arrScore[0]);
                sb.Append(".00</td>");
                sb.Append("<td>");
                sb.Append(percentMy);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentClass);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentGrade);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentArea);
                sb.Append("</td>");
                sb.Append("</tr>");
            }
            this.CognitiveLeveList.InnerHtml = sb.ToString();
            piechart = PageValidate.IsEmpty(piechart) ? "" : piechart.Substring(0, piechart.Length - 1);
            barchart = PageValidate.IsEmpty(barchart) ? "" : barchart.Substring(0, barchart.Length - 1);
        }

        private void sixPage(IList<StudentScoreExtendInfo> infos, StudentScoreExtendInfo myInfo)
        {
            IList<QuesTypeInfo> listQuestType = GetQuestType();
            IList<QuestionInfo> listQuestion = GetQuestion(myInfo.ExamPaperId);

            StringBuilder sb = new StringBuilder();
            foreach (QuesTypeInfo questype in listQuestType)
            {
                decimal questScoreCount = 0;
                IList<int> questIds = new List<int>();
                foreach (QuestionInfo quest in listQuestion)
                {
                    if (quest.QuesTypeId == questype.Id)
                    {
                        questScoreCount += quest.Score;
                        questIds.Add(quest.Id);
                    }
                }
                if (questIds.Count == 0)
                {
                    continue;
                }
                piechart1 += "['" + questype.Name + "'," + questIds.Count + "],";
                string[] arrScore = GetScoreByQuest(infos, myInfo.StudentId, myInfo.ClassId, myInfo.GradeId, myInfo.AreaId, questIds);
                string percentMy = "0";
                string percentClass = "0";
                string percentGrade = "0";
                string percentArea = "0";
                if (arrScore[0] != "0")
                {
                    percentMy = Math.Round(decimal.Parse(arrScore[0]) / questScoreCount * 100).ToString() + "%";
                }
                if (arrScore[1] != "0")
                {
                    percentClass = Math.Round(decimal.Parse(arrScore[1]) / (questScoreCount * int.Parse(arrScore[4])) * 100).ToString() + "%";
                }
                if (arrScore[2] != "0")
                {
                    percentGrade = Math.Round(decimal.Parse(arrScore[2]) / (questScoreCount * int.Parse(arrScore[5])) * 100).ToString() + "%";
                }
                if (arrScore[3] != "0")
                {
                    percentArea = Math.Round(decimal.Parse(arrScore[3]) / (questScoreCount * int.Parse(arrScore[6])) * 100).ToString() + "%";
                }
                barchart1 += "['" + questype.Name + "'," + percentMy.Replace("%", "") + "],";
                sb.Append("<tr>");
                sb.Append("<td align='left'>");
                sb.Append(questype.Name);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questIds.Count.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questScoreCount.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(arrScore[0]);
                sb.Append(".00</td>");
                sb.Append("<td>");
                sb.Append(percentMy);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentClass);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentGrade);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentArea);
                sb.Append("</td>");
                sb.Append("</tr>");
            }
            this.QuestTypeList.InnerHtml = sb.ToString();
            piechart1 = PageValidate.IsEmpty(piechart1) ? "" : piechart1.Substring(0, piechart1.Length - 1);
            barchart1 = PageValidate.IsEmpty(barchart1) ? "" : barchart1.Substring(0, barchart1.Length - 1);
        }

        private void sevenPage(IList<StudentScoreExtendInfo> infos, StudentScoreExtendInfo myInfo)
        {
            IList<DifficInfo> listDiffic = GetDiffic();
            IList<QuestionInfo> listQuestion = GetQuestion(myInfo.ExamPaperId);

            StringBuilder sb = new StringBuilder();
            foreach (DifficInfo diffic in listDiffic)
            {
                decimal questScoreCount = 0;
                IList<int> questIds = new List<int>();
                foreach (QuestionInfo quest in listQuestion)
                {
                    if (quest.DifficId == diffic.Id)
                    {
                        questScoreCount += quest.Score;
                        questIds.Add(quest.Id);
                    }
                }
                if (questIds.Count == 0)
                {
                    continue;
                }
                piechart2 += "['" + diffic.Name + "'," + questIds.Count + "],";
                string[] arrScore = GetClassScoreByQuest(infos, myInfo.StudentId, myInfo.ClassId, myInfo.GradeId, myInfo.AreaId, questIds);
                string percentMy = "0";
                string percentClass = "0";
                string percentGrade = "0";
                string percentArea = "0";
                if (arrScore[0] != "0")
                {
                    percentMy = Math.Round(decimal.Parse(arrScore[0]) / questScoreCount * 100).ToString() + "%";
                }
                if (arrScore[1] != "0")
                {
                    percentClass = Math.Round(decimal.Parse(arrScore[1]) / (questScoreCount * int.Parse(arrScore[4])) * 100).ToString() + "%";
                }
                if (arrScore[2] != "0")
                {
                    percentGrade = Math.Round(decimal.Parse(arrScore[2]) / (questScoreCount * int.Parse(arrScore[5])) * 100).ToString() + "%";
                }
                if (arrScore[3] != "0")
                {
                    percentArea = Math.Round(decimal.Parse(arrScore[3]) / (questScoreCount * int.Parse(arrScore[6])) * 100).ToString() + "%";
                }
                barchart2 += "['" + diffic.Name + "'," + percentMy.Replace("%", "") + "],";
                sb.Append("<tr>");
                sb.Append("<td align='left'>");
                sb.Append(diffic.Name);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questIds.Count.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(questScoreCount.ToString());
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(arrScore[0]);
                sb.Append(".00</td>");
                sb.Append("<td>");
                sb.Append(percentMy);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentClass);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentGrade);
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append(percentArea);
                sb.Append("</td>");
                sb.Append("</tr>");
            }
            this.DifficList.InnerHtml = sb.ToString();
            piechart2 = PageValidate.IsEmpty(piechart2) ? "" : piechart2.Substring(0, piechart2.Length - 1);
            barchart2 = PageValidate.IsEmpty(barchart2) ? "" : barchart2.Substring(0, barchart2.Length - 1);
        }

        private void ClassCount(IList<StudentScoreExtendInfo> infos, int classid)
        {
            decimal count = infos.Where(t => t.ClassId == classid).Sum(t => t.CountScore);
            StudentScoreExtendInfo info = infos.Where(t => t.ClassId == classid).OrderByDescending(t => t.CountScore).First();
            int rencount = infos.Where(t => t.ClassId == classid).Count();
            ViewClassEverage = Math.Round((count / rencount), 1).ToString();
            ViewClassNumber = rencount.ToString();
            ViewGClassMax = info.CountScore.ToString();

        }
        private void GradeCount(IList<StudentScoreExtendInfo> infos, int gradeid)
        {
            decimal count = infos.Where(t => t.GradeId == gradeid).Sum(t => t.CountScore);
            StudentScoreExtendInfo info = infos.Where(t => t.GradeId == gradeid).OrderByDescending(t => t.CountScore).First();
            int rencount = infos.Where(t => t.GradeId == gradeid).Count();
            ViewGradeEverage = Math.Round((count / rencount), 1).ToString();
            ViewGradeNumber = rencount.ToString();
            ViewGradeMax = info.CountScore.ToString();
        }
        private void AreaCount(IList<StudentScoreExtendInfo> infos, int areaid)
        {
            decimal count = infos.Where(t => t.AreaId == areaid).Sum(t => t.CountScore);
            StudentScoreExtendInfo info = infos.Where(t => t.AreaId == areaid).OrderByDescending(t => t.CountScore).First();
            int rencount = infos.Where(t => t.AreaId == areaid).Count();
            ViewAreaEverage = Math.Round((count / rencount), 1).ToString();
            ViewAreaMax = info.CountScore.ToString();
            ViewAreaNumber = rencount.ToString();
        }

        private string[] GetClassScoreByQuest(IList<StudentScoreExtendInfo> infos, int sid, int classid, int gradeid, int areaid, IList<int> questid)
        {
            decimal myScore = 0, classScore = 0, gradeScore = 0, areaScore = 0;
            int classNum = 0, gradeNum = 0, areaNum = 0;
            foreach (StudentScoreExtendInfo info in infos)
            {
                IList<ScoreInfo> scoreInfos = ScoreHelper.GetScoreList(info.QuestItemScore);
                scoreInfos = scoreInfos.Where(t => GetArray<int>.Get(questid).Contains(t.Id)).ToList();
                decimal score = 0;
                foreach (ScoreInfo scoreInfo in scoreInfos)
                {
                    if (!PageValidate.IsEmpty(scoreInfo.Score))
                    {
                        score += decimal.Parse(scoreInfo.Score);
                    }
                }
                if (info.StudentId == sid)
                {
                    myScore = score;
                }
                if (info.ClassId == classid)
                {
                    classScore += score;
                    classNum++;
                }
                if (info.GradeId == gradeid)
                {
                    gradeScore += score;
                    gradeNum++;
                }
                if (info.AreaId == areaid)
                {
                    areaScore += score;
                    areaNum++;
                }
            }
            return new string[] { myScore.ToString(), classScore.ToString(), gradeScore.ToString(), areaScore.ToString(), classNum.ToString(), gradeNum.ToString(), areaNum.ToString() };
        }

        private void LoadQuestion(int exampaperid)
        {
            string[] hanzi = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "二十一", "二十二", "二十三", "二十四", "二十五", "二十六", "二十七", "二十八", "二十九", "三十" };
            IList<PaperQuestionInfo> infos = new List<PaperQuestionInfo>();
            infos = Question.GetList(exampaperid);
            if (ExamPaper_Info.TestPaperPolicyMainId == null)
            {
                ExamPaper_Info.TestPaperPolicyMainId = 0;
            }
            IList<TestPaperPolicySubInfo> tpinfo = TestPaperPolicySub.GetList((int)ExamPaper_Info.TestPaperPolicyMainId);
            StringBuilder sb = new StringBuilder();
            int i = 0;
            int a = 1;
            foreach (TestPaperPolicySubInfo info in tpinfo)
            {
                XmlQuestion xq = XmlQuestionHelper.GetXmlQuestionInfo(info.Content);
                sb.Append("<h3>");
                sb.Append(hanzi[i]);
                sb.Append("、");
                sb.Append(QuesType.GetQuesTypeInfoById(int.Parse(xq.Type)).Name);
                sb.Append("共 ");
                sb.Append(xq.AllCount.ToString());
                sb.Append(" 小题 ");
                if (xq.SingleScore != null && xq.SingleScore.Count > 0)
                {
                    sb.Append("每小题 ");
                    sb.Append(string.Join(",", ArrayHelper.ConvertToStringArray(GetArray<decimal>.Get(xq.SingleScore))));
                    sb.Append(" 分");
                }
                sb.Append("总分为：");
                sb.Append(xq.AllScore.ToString());
                sb.Append("分");
                sb.Append("</h3>");
                IList<PaperQuestionInfo> tInfos = infos.Where(t => t.SubPolicyId == info.Id).ToList();
                foreach (PaperQuestionInfo qinfo in tInfos)
                {
                    sb.Append("<div class='block'>");
                    sb.Append("<span class='num'>" + a.ToString() + "、</span>");
                    sb.Append("<div class='content'>");
                    qinfo.Title = ClearHtml(qinfo.Title);
                    if (xq.SingleScore.Count > 1)
                    {
                        qinfo.Title = WiterScore(qinfo.Title, qinfo.Score);
                    }
                    sb.Append(qinfo.Title);
                    sb.Append("</div>");
                    sb.Append("<div class='answer'><span class='num'>参考答案：</span>");
                    sb.Append("<div class='content'>");
                    sb.Append(qinfo.Answer);
                    sb.Append("</div></div>");
                    sb.Append("<div class='isclear'></div></div>");
                    a++;
                }
                i++;
            }
            TempList.InnerHtml = sb.ToString();
        }

        private string WiterScore(string InputStr, decimal Score)
        {
            string t = InputStr;
            string[] strArray = new Regex("<.[^>]*?>(.*?)</.*?>", RegexOptions.IgnoreCase).Split(t);
            foreach (string item in strArray)
            {
                string temp = CodingHtml(item);
                temp = Regex.Replace(temp, "{{.*?}}", "");
                if (temp.Trim().Length > 0)
                {
                    if (!temp.Trim().StartsWith("{{"))
                    {
                        if (t.IndexOf(temp.Trim()) > -1)
                        {
                            t = t.Replace(temp, "(" + Score.ToString() + ")" + temp);
                            return t;
                        }
                    }
                }
            }
            return t;
        }

        /// <summary>
        /// 编码Html
        /// </summary>
        /// <param name="InputStr">输入字符串</param>
        /// <returns></returns>
        private string CodingHtml(string InputStr)
        {
            if (InputStr.Length > 0)
            {
                string t = InputStr;
                t = t.Replace("&nbsp;", "{{空格}}");
                t = Regex.Replace(t, "<(.*?)>", "{{($1)}}");
                return t;
            }
            else
            {
                return InputStr;
            }
        }

        /// <summary>
        /// 解码Html
        /// </summary>
        /// <param name="InputStr"></param>
        /// <returns></returns>
        private string DecodingHtml(string InputStr)
        {
            if (InputStr.Length > 0)
            {
                string t = InputStr;
                t = t.Replace("{{空格}}", "&nbsp;");
                t = Regex.Replace(t, "{{(.*?)}}", "<$1>");
                return t;
            }
            else
            {
                return InputStr;
            }
        }

        private string ClearHtml(string InputStr)
        {
            string Temp = Module_String.clearhtml(InputStr, "span");
            Temp = Temp.Replace("<p>&nbsp;</p>", "");
            Temp = Module_String.DelStr("style=\"", "\"", Temp);
            Temp = Module_String.DelStr("class=\"", "\"", Temp);
            return Temp;
        }
        private string AnswerAnalyze(StudentScoreExtendInfo myInfo, int exampaperid)
        {
            StringBuilder sb = new StringBuilder();
            IList<ScoreInfo> scoreInfos = ScoreHelper.GetScoreList(myInfo.QuestItemScore);
            IList<PaperQuestionInfo> infos = new List<PaperQuestionInfo>();
            ExamPaperInfo examPaperInfo = BAL.ExamPaper.GetT1(exampaperid);
            infos = Question.GetList(examPaperInfo.Id);
            if (examPaperInfo.TestPaperPolicyMainId == null)
            {
                examPaperInfo.TestPaperPolicyMainId = 0;
            }
            IList<TestPaperPolicySubInfo> tpinfo = TestPaperPolicySub.GetList((int)examPaperInfo.TestPaperPolicyMainId);
            int a = 1;
            foreach (TestPaperPolicySubInfo info in tpinfo)
            {
                IList<PaperQuestionInfo> tInfos = infos.Where(t => t.SubPolicyId == info.Id).ToList();
                foreach (PaperQuestionInfo qinfo in tInfos)
                {
                    if (scoreInfos.Count > 0)
                    {
                        ScoreInfo scoreInfo = scoreInfos.Single(t => t.Id == qinfo.Id);
                        if (decimal.Parse(scoreInfo.Score) != qinfo.Score)
                        {
                            string knowname = Knowledge.GetKnowledgeInfoById(qinfo.KnowId).Name;
                            sb.Append("<tr>");
                            sb.Append("<td>");
                            sb.Append(a.ToString());
                            sb.Append("</td>");
                            sb.Append("<td class='text_left'>");
                            sb.Append(knowname);
                            sb.Append("</td>");
                            sb.Append("<td>");
                            sb.Append(qinfo.Score.ToString());
                            sb.Append("</td>");
                            sb.Append("<td>");
                            sb.Append(scoreInfo.Score);
                            sb.Append(".00</td>");
                            sb.Append("<td class='text_left' style='word-break:break-all;overflow:auto;'>");
                            sb.Append(scoreInfo.Answer);
                            sb.Append("</td>");
                            sb.Append("<td class='text_left' style='word-break:break-all;overflow:auto;'>");
                            sb.Append(qinfo.Answer);
                            sb.Append("</td>");
                            sb.Append("</tr>");
                        }
                        a++;
                    }
                }
            }
            return sb.ToString();
        }

        private string[] GetScoreByQuest(IList<StudentScoreExtendInfo> infos, int sid, int classid, int gradeid, int areaid, IList<int> questid)
        {
            decimal myScore = 0, classScore = 0, gradeScore = 0, areaScore = 0;
            int classNum = 0, gradeNum = 0, areaNum = 0;
            foreach (StudentScoreExtendInfo info in infos)
            {
                IList<ScoreInfo> scoreInfos = ScoreHelper.GetScoreList(info.QuestItemScore);
                scoreInfos = scoreInfos.Where(t => GetArray<int>.Get(questid).Contains(t.Id)).ToList();
                decimal score = 0;
                foreach (ScoreInfo scoreInfo in scoreInfos)
                {
                    if (!PageValidate.IsEmpty(scoreInfo.Score))
                    {
                        score += decimal.Parse(scoreInfo.Score);
                    }
                }
                if (info.StudentId == sid)
                {
                    myScore = score;
                }
                if (info.ClassId == classid)
                {
                    classScore += score;
                    classNum++;
                }
                if (info.GradeId == gradeid)
                {
                    gradeScore += score;
                    gradeNum++;
                }
                if (info.AreaId == areaid)
                {
                    areaScore += score;
                    areaNum++;
                }
            }
            return new string[] { myScore.ToString(), classScore.ToString(), gradeScore.ToString(), areaScore.ToString(), classNum.ToString(), gradeNum.ToString(), areaNum.ToString() };
        }
        private IList<KnowledgeInfo> GetKnowledgeMode(int subjectid)
        {
            IList<KnowledgeInfo> infos = new List<KnowledgeInfo>();
            infos = Knowledge.GetKnowledgeInfosBySubjectId(subjectid).Where(t => t.Keyword.Length == 1).ToList();
            foreach (KnowledgeInfo info in infos)
            {
                info.ChildKnowledgeInfos = Knowledge.GetKnowledgeInfos(info.Id);
                foreach (KnowledgeInfo subInfo in info.ChildKnowledgeInfos)
                {
                    subInfo.ChildKnowledgeInfos = Knowledge.GetKnowledgeInfos(subInfo.Id);
                }
            }
            return infos;
        }
        private IList<KnowledgeInfo> GetKnowledgeModePoint(int subjectid)
        {
            IList<KnowledgeInfo> infos = new List<KnowledgeInfo>();
            infos = Knowledge.GetKnowledgeInfosBySubjectId(subjectid).Where(t => t.Keyword.Length == 5).ToList();
            foreach (KnowledgeInfo info in infos)
            {
                info.ParentKnowledgeInfo = Knowledge.GetKnowledgeInfo(info);
                if (info.ParentKnowledgeInfo != null)
                {
                    info.ParentKnowledgeInfo.ParentKnowledgeInfo = Knowledge.GetKnowledgeInfo(info.ParentKnowledgeInfo);
                }
            }
            return infos;
        }
        private IList<CognitiveLevelInfo> GetCognitiveLeve()
        {
            IList<CognitiveLevelInfo> infos = new List<CognitiveLevelInfo>();
            infos = CognitiveLevel.GetList(0);
            return infos;
        }
        private IList<QuesTypeInfo> GetQuestType()
        {
            IList<QuesTypeInfo> infos = new List<QuesTypeInfo>();
            infos = QuesType.GetQuesTypeInfos(0, 0);
            return infos;
        }
        private IList<DifficInfo> GetDiffic()
        {
            IList<DifficInfo> infos = new List<DifficInfo>();
            infos = Diffic.GetDifficInfos(0, 0);
            return infos;
        }
        private IList<QuestionInfo> GetQuestion(int exampaperid)
        {
            IList<QuestionInfo> infos = new List<QuestionInfo>();
            infos = Question.GetQuestions(exampaperid, "", "", "", "", "", "", "", "", "", 0, 0);
            return infos;
        }
    }
}
